package com.service.impl;

import com.bean.entity.StudentStatus;
import com.bean.pojo.PageAssistant;
import com.bean.vo.StudentStatusVo;
import com.dao.StudentStatusMapper;
import com.service.StudentStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class StudentStatusServiceImpl implements StudentStatusService {
    @Autowired
    private StudentStatusMapper studentStatusMapper;
    @Override
    public int save(StudentStatus t) throws Exception {
        int insert = studentStatusMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("学生学籍添加失败，请正确操作！");
    }

    @Override
    public int remove(StudentStatus t) throws Exception {
        int delete = studentStatusMapper.delete(t);

        if (delete==1) return 1;
        throw new Exception("学生学籍删除失败！");
    }

    @Override
    public int modify(StudentStatus t) throws Exception {
        int update = studentStatusMapper.update(t);
        if (update== 1)  return 1;
        throw new Exception("学生学籍修改失败，请正确操作！");
    }

    @Override
    public StudentStatusVo unique(StudentStatus t) throws Exception {
        List<StudentStatusVo> select = studentStatusMapper.select(t);
        if (select.size()!=1) throw new Exception("您要查的学籍暂未找到！");
        return select.get(0);
    }

    @Override
    public List<StudentStatusVo> query(StudentStatus t) {
        return studentStatusMapper.select(t);
    }

    @Override
    public PageAssistant<StudentStatusVo> queryByPage(Map<String, Object> map, PageAssistant<StudentStatusVo> pa) {
        //查询并设置总记录数
        pa.setCount(studentStatusMapper.selectCount(map));

        //添加分页参数
        map.put("startCode",pa.getStartCode());
        map.put("pageSize",pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(studentStatusMapper.selectByPage(map));

        return pa;
    }
}
